package com.ruyuan.eshop.manager.controller.account;

import com.ruyuan.eshop.framework.context.LoginUser;
import com.ruyuan.eshop.framework.context.LoginUserContext;
import com.ruyuan.eshop.framework.core.JsonResult;
import com.ruyuan.eshop.manager.domain.dto.UserAccountDTO;
import com.ruyuan.eshop.manager.domain.request.UserLoginRequest;
import com.ruyuan.eshop.manager.service.AccountManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 会员买家用户账号管理Controller组件
 * </p>
 *
 * @author pwd
 * @version 1.0
 */
@Api(tags = "平台管理员用户账号管理")
@RestController
@RequestMapping("/admin/v1/manager/account")
public class ManagerLoginController {

    @Autowired
    private AccountManagerService accountManagerService;

    /**
     * 用户登录
     * @param userLoginRequest 账号密码信息
     * @return token
     */
    @ApiOperation("用户登录")
    @PostMapping("/login")
    public JsonResult<String> login(@RequestBody UserLoginRequest userLoginRequest){
        String token = accountManagerService.login(userLoginRequest);
        return JsonResult.buildSuccess(token);
    }

    /**
     * 用户账号信息查询
     * @return
     */
    @ApiOperation("用户账号信息查询")
    @GetMapping("/detail")
    public UserAccountDTO detail() {
        LoginUser loginUser = LoginUserContext.getLoginUser();
        UserAccountDTO userAccountDTO = accountManagerService.detail(loginUser.getUsername());
        return userAccountDTO;
    }

}